package cn.ydt.ydt.user.webapi.controller;

import cn.ydt.ydt.common.resful.JsonResult;
import cn.ydt.ydt.pojo.user.dto.FamilyAddDTO;
import cn.ydt.ydt.pojo.user.dto.FamilyUpdateDTO;
import cn.ydt.ydt.user.service.IFamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/family")
@Api(tags = "家庭模块")
public class FamilyController {

    @Autowired(required = false)
    IFamilyService familyService;

    @PostMapping("/add")
    @ApiOperation("家人信息添加")
    public JsonResult add(@Validated @RequestBody FamilyAddDTO familyAddDTO) throws ParseException {
        familyService.add(familyAddDTO);
        return JsonResult.ok("添加成功！");
    }

    @PostMapping("/update")
    @ApiOperation("修改更新家人信息")
    public JsonResult update(@Validated @RequestBody FamilyUpdateDTO familyUpdateDTO){
        familyService.update(familyUpdateDTO);
        return JsonResult.ok("修改成功");
    }

    @PostMapping("/select")
    @ApiOperation("查询家人信息")
    public JsonResult<List> select( String familyId){
        List<FamilyUpdateDTO> familyUpdateDTO = familyService.select(familyId);
        familyService.select(familyId);
        return JsonResult.ok(familyUpdateDTO,"查看成功");
    }
}
